package com.lambkit.module.cms.core.search.impl;

import java.text.DecimalFormat;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;
import com.lambkit.module.cms.core.km.FileStateEnum;
import com.lambkit.module.cms.rpc.model.CmsFile;

public class FileSearchRecord extends Record {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String fileText;
	private List<String> fileKeyWords;
	
	public FileSearchRecord() {
		// TODO Auto-generated constructor stub
	}
	
	public FileSearchRecord(CmsFile file) {
		setColumns(file);
	}

	public java.lang.Long getFileId() {
		return this.get("file_id");
	}

	public void setFileId(java.lang.Long fileId) {
		this.set("file_id", fileId);
	}
	public java.lang.String getFileName() {
		return this.get("file_name");
	}

	public void setFileName(java.lang.String fileName) {
		this.set("file_name", fileName);
	}
	public java.lang.Long getFileSize() {
		return this.get("file_size");
	}

	public void setFileSize(java.lang.Long fileSize) {
		this.set("file_size", fileSize);
	}
	public java.lang.String getFileExt() {
		return this.get("file_ext");
	}

	public void setFileExt(java.lang.String fileExt) {
		this.set("file_ext", fileExt);
	}
	public java.lang.Long getFileUserId() {
		return this.get("file_user_id");
	}

	public void setFileUserId(java.lang.Long fileUserId) {
		this.set("file_user_id", fileUserId);
	}
	public java.lang.String getFileUuid() {
		return this.get("file_uuid");
	}

	public void setFileUuid(java.lang.String fileUuid) {
		this.set("file_uuid", fileUuid);
	}
	public java.lang.String getFilePath() {
		return this.get("file_path");
	}

	public void setFilePath(java.lang.String filePath) {
		this.set("file_path", filePath);
	}
	public java.lang.Integer getFileState() {
		return this.get("file_state");
	}

	public void setFileState(java.lang.Integer fileState) {
		this.set("file_state", fileState);
	}
	public java.lang.Long getFileCategoryId() {
		return this.get("file_category_id");
	}

	public void setFileCategoryId(java.lang.Long fileCategoryId) {
		this.set("file_category_id", fileCategoryId);
	}
	public java.util.Date getFileCreateTime() {
		return this.get("file_create_time");
	}

	public void setFileCreateTime(java.util.Date fileCreateTime) {
		this.set("file_create_time", fileCreateTime);
	}
	public java.lang.String getFileBrief() {
		return this.get("file_brief");
	}

	public void setFileBrief(java.lang.String fileBrief) {
		this.set("file_brief", fileBrief);
	}

	public String getCategoryName() {
		return this.get("category");
	}

	public void setCategoryName(String categoryName) {
		this.set("category", categoryName);
	}

	public String getUserName() {
		return this.get("username");
	}

	public void setUserName(String userName) {
		this.set("username", userName);
	}

	public String getFileStateStr() {
		return FileStateEnum.stateOf(getFileState()).getStateInfo();
	}

	public String getHiddenedFileName() {
		String str = getFileName();
		if (str.length() > 19) {
			//String ext = str.substring(str.lastIndexOf("."), str.length());
			str = str.substring(0, 15)+"...";
		}

		return str;
	}

	public String getFileSizeFormat() {
		if (getFileSize() != null) {

			return getDataSize(getFileSize());
		}
		return "0";
	}

	public void setFileSizeFormat(String fileSizeFormat) {
		this.set("file_size_format", fileSizeFormat);
	}

	/**
	 * 文件大小格式
	 * 
	 * @param size
	 * @return
	 */
	public String getDataSize(long size) {
		DecimalFormat formater = new DecimalFormat("####.00");
		if (size < 1024) {
			return size + " bytes";
		} else if (size < 1024 * 1024l) {
			float kbsize = size / 1024f;
			return formater.format(kbsize) + " KB";
		} else if (size < 1024 * 1024 * 1024l) {
			float mbsize = size / 1024f / 1024f;
			return formater.format(mbsize) + " MB";
		} else if (size < 1024 * 1024 * 1024 * 1024l) {
			float gbsize = size / 1024f / 1024f / 1024f;
			return formater.format(gbsize) + " GB";
		} else {
			return "size: error";
		}
	}
	
	public String getFileText() {
		return fileText;
	}
	public void setFileText(String fileText) {
		this.fileText = fileText;
	}
	public List<String> getFileKeyWords() {
		return fileKeyWords;
	}
	public void setFileKeyWords(List<String> fileKeyWords) {
		this.fileKeyWords = fileKeyWords;
	}
	@Override
	public String toString() {
		return super.toString() +"FileInfoVO [fileStateStr=" + getFileStateStr() + ", fileSizeFormat=" + getFileSizeFormat() + ", fileUserName="
				+ getUserName() + "]" + "LuceneSearchVo [fileText=" + fileText + ", fileKeyWords=" + fileKeyWords + "]";
	}
	

}
